package ui

import (
	"embed"
	"errors"
	"io/fs"
	"path"
	"path/filepath"
	"strings"
)

//go:embed demo
var Dist embed.FS

type WebUi struct {
	Fs   embed.FS
	Path string // 设置embed文件到静态资源的相对路径，也就是embed注释里的路径
}

func (w *WebUi) Open(name string) (fs.File, error) {
	if filepath.Separator != '/' && strings.ContainsRune(name, filepath.Separator) {
		return nil, errors.New("http: invalid separator in file Path")
	}
	fullName := filepath.Join(w.Path, filepath.FromSlash(path.Clean("/"+name)))
	return w.Fs.Open(fullName)
}
